import torch.nn as nn
import torch
import torch.nn.functional as F

class DDRHead(nn.Module):
    def __init__(self,in_channels,feats_channels,num_classes,dropout_ratio=0.1, align_corners=False):
        super(DDRHead,self).__init__()
        self.bn1 = nn.SyncBatchNorm(in_channels)
        self.conv1 = nn.Conv2d(
            in_channels,
            feats_channels,
            kernel_size=3,
            padding=1)
        self.bn2 = nn.SyncBatchNorm(feats_channels)
        self.relu = nn.ReLU()
        if dropout_ratio > 0:
            self.dropout = nn.Dropout2d(dropout_ratio)
        else:
            self.dropout = None

        self.conv_seg = nn.Conv2d(feats_channels, num_classes, kernel_size=1)

    def forward(self, x):
        x = self.conv1(self.relu(self.bn1(x)))
        x = self.relu(self.bn2(x))
        if self.dropout is not None:
            x = self.dropout(x)
        x = self.conv_seg(x)
        return x


class DDRAUCHead(nn.Module):
    def __init__(self,in_channels,feats_channels,num_classes,dropout_ratio=0.1, align_corners=False):
        super(DDRAUCHead,self).__init__()
        self.bn1 = nn.SyncBatchNorm(in_channels)
        self.conv1 = nn.Conv2d(
            in_channels,
            feats_channels,
            kernel_size=3,
            padding=1)
        self.bn2 = nn.SyncBatchNorm(feats_channels)
        self.relu = nn.ReLU()
        if dropout_ratio > 0:
            self.dropout = nn.Dropout2d(dropout_ratio)
        else:
            self.dropout = None

        self.conv_seg = nn.Conv2d(feats_channels, num_classes, kernel_size=1)

    def forward(self, x):
        x = self.conv1(self.relu(self.bn1(x)))
        x = self.relu(self.bn2(x))
        if self.dropout is not None:
            x = self.dropout(x)
        x = self.conv_seg(x)
        return x
